package graph.drawingshapes.tools
{
	import common.interfaces.INameable;
	
	import graph.drawingshapes.DrawingShapeBase;
	import graph.drawingshapes.RedrawEvent;

	public class DrawingTool extends DrawingShapeBase implements INameable
	{
		public static const NAME:String = "DrawingTool"
		public virtual function get getName():String 
		{
			return NAME;
		}				
		
		public static const DefaultColor:uint = 0x000000;
		private var _color:uint = DefaultColor;
		public virtual function get color():uint
		{
			return this._color;
		}
		public virtual function set color(value:uint):void
		{
			if (value != this._color)
			{
				this._color = value;
				dispatchEvent(new RedrawEvent());
			}
		}
		
		public static const DefaultAlpha:Number = 1.0;
		public override function get alpha():Number
		{
			return super.alpha;
		}
		
		public override function set alpha(value : Number) : void
		{
			if (value != this.alpha)
			{
				super.alpha = value;
				dispatchEvent(new RedrawEvent());
			}
		}
		
		public function DrawingTool(color:uint = DefaultColor, alpha:Number = DefaultAlpha)
		{
			super();
			this.color = color;
			this.alpha = alpha;
			dispatchEvent(new RedrawEvent());
		}
		
		protected override function initDrawing():void
		{
			super.initDrawing();
			this.graphics.lineStyle(1, color, alpha, false);
			this.graphics.beginFill(color, alpha);
		}
		
		protected override function endDrawing():void
		{
			super.endDrawing();
			this.graphics.endFill();
		}
		
		// TODO : use this code in manager
		/* public virtual function drawLine(graphics:Graphics, startPoint:Point, endPoint:Point):Graphics
		{
			var dx:Number = endPoint.x - startPoint.x;
			var dy:Number = endPoint.y - startPoint.y;
			//if nothing to draw...
			if (dx==0 && dy==0) return graphics;
			
			var sign:Number;
			
			var currX:Number;
			var currY:Number;
			var i:Number;
			
			if (Math.abs(dx)>=Math.abs(dy))
			{
				sign = dx/Math.abs(dx);
				for (i = 1; i < Math.abs(dx); ++i)
				{
					currX = startPoint.x + (sign*i);
					currY = ((currX - startPoint.x)/dx)*dy + startPoint.y;
					this.draw(graphics, currX, currY);
				}
			}
			else
			{
				sign = dy/Math.abs(dy);
				for (i = 1; i < Math.abs(dy); ++i)
				{
					currY = startPoint.y + (sign*i);
					currX = ((currY - startPoint.y)/dy)*dx + startPoint.x;
					this.draw(graphics, currX, currY);
				}
			}
			
			return graphics;
		} */
	}
}